package com.itheima.web;

import com.itheima.bean.Orders;
import com.itheima.common.R;
import com.itheima.service.OrderService;
import com.itheima.service.ShoppingCartService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "订单管理模块")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @Autowired
    private ShoppingCartService shoppingCartService;


    /**
     * 提交订单
     * @param order
     * @return
     */
    @PostMapping("/order/submit")
    public R submitOrder(@RequestBody Orders order){

        int row = orderService.add(order);

        if(row > 0 ){

            shoppingCartService.clean();

            return R.success("提交订单成功！");
        }
        return R.success("提交订单失败！");

    }
}
